def d(a):    
  if a == 1: return False    
  c = True    
  f = a - 1    
  while f > 1:    
      if not a % f:    
          c = False                
          break   
      f -= 1        
  return c   

n = input()  
r = []  
for i in range(len(n)):  
  for f in range(i + 1,len(n) + 1):  
      a = int(n[i:f]) 
      if d(a):  
          r += [a]  
print(max(r) if r else 0)